﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Reflection;
using System.Text;
using T.FAS.Action.MetaData.Entity;
using T.FAS.Base.Dao;
using Teld.Core.DAC.Service;

namespace T.FAS.Action.Dev.Dao
{
    public class ActionACLDetailELBDao : DaoService<ACLDetail>
    {
        public override string TableName => "FAS_ACLDetail";
        public override string IDColumnName => "ID";
        public override List<string> ExceptColumnName
            => DaoUtil.GetExceptionColumn<ACLDetail>(
                new List<string>
                {
                }
            );
        public ActionACLDetailELBDao() : base()
        {
            DBName = "TeldFAS";
        }
        public override Dictionary<string, PropertyInfo> GetColumns()
        {
            return DaoServiceExtension.GetAllColumns<ACLDefine>(base.GetColumns());
        }
        public override ACLDetail ConvertToObject(Dictionary<string, PropertyInfo> columns, DataRow row)
        {
            if (columns.ContainsKey("ACLType"))
                columns.Remove("ACLType");

            var data = base.ConvertToObject(columns, row);

            data.ACLType = (ACLType)Enum.Parse(typeof(ACLType), Convert.ToString(row["ACLType"]));

            return data;
        }

        public override Dictionary<string, object> GetDataMapping(ACLDetail data)
        {
            var mapping = base.GetDataMapping(data);
            mapping.Remove("ACLType");
            mapping.Add("ACLType", (int)data.ACLType);

            return mapping;
        }
        /// <summary>
        /// 根据ACLDefineID获取ACLDetail信息
        /// </summary>
        /// <param name="aclDefineId"></param>
        /// <returns></returns>
        public List<ACLDetail> GetACLDetailsByACLDefID(string aclDefineId)
        {
            var result = base.GetObjectsByFilter($"ACLDefineID='{aclDefineId}'");
            var list = new List<ACLDetail>();
            if (result != null && result.Count > 0)
            {
                result.ForEach(x => list.Add(x as ACLDetail));
            }
            return list;
        }

    }
}
